<?php

namespace App\Http\Middleware\Admin;

use Closure , Session , Cookie , Config;

use Illuminate\Http\Response;

class StoreAuth {

    public function handle($request , Closure $next , $gurad = null){

        $sessionKey = Cookie::get(Config::get('session.store_cookie'));

        $sessionData = Session::get($sessionKey);

        if(!isset($sessionData['userInfo']) || empty($sessionData['userInfo'])){
            if($request->ajax()){
                return response()->json(['code' => -1000 , 'msg' => '未登录']);
            }else{
                return redirect('/store/login');
            }
        }

        $user = $sessionData['userInfo'];


        global $suuid;
        $suuid = $user['id'];


        return $next($request);
    }
}